<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="com.carrentalssm.service.CarListService"%>
<%@page import="java.util.List"%>
<%@page import="com.carrentalssm.entity.CarList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>汽车租赁网</title>
<script type="text/javascript" src="<%=request.getContextPath() %>/frame/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="<%=request.getContextPath() %>/frame/bootstrap-3.4.1-dist/css/bootstrap.css">
<script type="text/javascript" src="<%=request.getContextPath() %>/frame/bootstrap-3.4.1-dist/js/bootstrap.js"></script>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/css/common.css" />
<style type="text/css">
	body{
		background-image: url("images/background.jpg");
		overflow: hidden;
	}
	.login-div{
		rgba(217, 237, 247);
		width: 600px;
		box-sizing: border-box;
		margin: 0px auto;
		padding: 20px 40px;
	}
	.login-title{
		text-align: center;
		font-size: 30px;
	}
	.form-item{
		box-sizing: border-box;
		width: 100%;
		height: 35px;
		margin-top: 15px;
		padding: 0px 5px;
	}
</style>
<style>
	.car{
		width: 100%;
		height: 100px;
		margin-top: 20px;
		border: 1px solid #bebebe;
		background-color: #ffffff;
		padding: 0px 20px;
	}
	.model-title{
		display: inline-block;
		width: 50px;
	}
	.model-text {
		display: inline-block;
		line-height: 100px;
		width: 150px;
		font-size: 30px;
	}
	.number-title{
		display: inline-block;
		width: 50px;
	}
	.number-text{
		display: inline-block;
		line-height: 100px;
		width: 80px;
		font-size: 30px;
	}
	.price-title{
		display: inline-block;
		width: 120px;
	}
	.price-text{
		display: inline-block;
		line-height: 100px;
		width: 200px;
		font-size: 30px;
	}
	.select-button{
		width: 100px;
		height: 30px;
	}
</style>
</head>
<body>
	<%
	Object loginUser = request.getSession().getAttribute("user");
	if (loginUser == null) {
		response.sendRedirect(request.getContextPath()+"/login.jsp");
		return;
	}
	%>
	<div class="head">
		<div class="head-content">
			<h2>小彭租车！</h2>
			<a href="<%=request.getContextPath() %>/index.jsp">首页</a>
			<a href="<%=request.getContextPath() %>/carRentalList.jsp">我的订单</a>
			<a href="<%=request.getContextPath() %>/userUpdate.jsp">个人信息</a>
			<a href="<%=request.getContextPath() %>/logout">退出</a>
		</div>
	</div>
	<div class="main">
		<div class="main-content">
			<%
				WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
				CarListService carListService = (CarListService) context.getBean("carListService");
				List<CarList> carLists = carListService.selectHaveNumber();
				for (CarList carList : carLists) {
					out.print("<div class='car'>");
					out.print("<span class='model-title'>车型</span><span class='model-text'>" + carList.getModel() + "</span>");
					out.print("<span class='number-title'>库存</span><span class='number-text'>" + carList.getNumber() + "</span>");
					out.print("<span class='price-title'>单价（元/日）</span><span class='price-text'>" + carList.getPrice() + "</span>");
					out.print("<a href='carRentalSelectNumAndDate.jsp?id=" + carList.getId() + "&num=1'><button class='select-button btn btn-success'>选择</button></a>");
					out.print("</div>");
				}
			%>
		</div>
	</div>
</body>
</html>